/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistentie;

import domein.Episode;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Element;

/**
 *
 * @author vuokko
 */
class EpisodeMapper {

    List<Episode> getEpisodes(Element e) {
        ArrayList<Episode> l = new ArrayList<>();

        for (Object o : e.getChild("episodes").getChildren("episode")) {
            Element el = (Element) o;
            l.add(new Episode(el.getChildText("identifier"), el.getChildText("title"), Boolean.valueOf(el.getChildText("watched"))));
        }

        return l;
    }

    Element getEpisodesAsElement(List<Episode> l) {
        Element episodes = new Element("episodes");
        for (Episode e: l) {
            Element epi = new Element("episode");        
            epi.addContent(new Element("identifier").setText(e.getIdentifier()));
            if (e.getTitle() != null) { epi.addContent(new Element("title").setText(e.getTitle())); }
            epi.addContent(new Element("watched").setText(Boolean.toString(e.isWatched())));           
            episodes.addContent(epi);
        }
        return episodes;
    }
}